#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;
const int INF = 1e9;

int n;
int a[N];
int dp[N][3];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) rep(j, 0, 2) dp[i][j] = INF;
  dp[1][a[1] + 1] = 0;
  rep(i, 2, n) {
    rep(j, 0, 2) {
      rep(k, 0, j) {
        // dp[i - 1][k] - a[i] - dp[i][j]
        if (k == 1 && a[i] + 1 == j) dp[i][j] = min(dp[i][j], dp[i - 1][k]);
        if (k == 0 && a[i] + 1 >= j)
          dp[i][j] = min(dp[i][j], dp[i - 1][k] + a[i] + 1 - j);
        if (k == 2 && a[i] + 1 <= j)
          dp[i][j] = min(dp[i][j], dp[i - 1][k] + j - a[i] - 1);
      }
    }
  }
  int ans = min({dp[n][0], dp[n][1], dp[n][2]});
  if (ans >= INF)
    cout << "BRAK";
  else
    cout << ans;
  return 0;
}